package com.audi.activity;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.audi.R;
import com.audi.BaseActivity;
import com.audi.adapter.PlaceDeviceCardAdapter;
import com.audi.adapter.SQLiteAsusNewHelper;
import com.audi.adapter.SceneAdapter;
import com.audi.dslv.DragSortController;
import com.audi.dslv.DragSortListView;
import com.audi.dslv.DragSortListView.DropListener;
import com.audi.dto.DeviceItem;
import com.audi.dto.PlaceItem;
import com.audi.dto.SceneItem;
import com.audi.utils.Constants;
import com.audi.view.AudiDialog;
import com.audi.view.DeviceUpdatePhoto;
import com.audi.view.InfoOfPlaceView;

@SuppressLint("CutPasteId")
public class PlaceCardDetailActivity extends BaseActivity implements
		OnClickListener, OnMenuItemClickListener, OnCheckedChangeListener {
	// hoangnt10
	private Context mContext;
	private SQLiteAsusNewHelper mSQLHelper;
	private ArrayList<DeviceItem> mDeviceList;
	private InfoOfPlaceView mInfoOfPlace;

	// private ListView mDeviceListView;

	private DragSortListView mInfoOfPlaceListView;
	private PlaceDeviceCardAdapter mDeviceAdapter;
	private ArrayList<PlaceItem> mInfoOfPlaceList;
	// update photo
	private DeviceUpdatePhoto mDeviceUpdatePhoto;
	private ArrayList<SceneItem> mSceneList;
	private DragSortListView mSceneListView, mDeviceListView;
	private SceneAdapter mSceneAdapter;
	private DragSortController mController, mControllerDevice;
	private CheckBox mchkWhite, mchkRed, mchkOrange, mchkYellow;
	private CheckBox mchkSilver, mchkSkyBlue, mchkSpringGreen, mchkYellowGreen;
	private AudiDialog dialogSelectColor;
	private Button mBtnPlaceInfo, mBtnPlaceDevice, mBtnPlaceScene;
	private SceneItem mAddItemScene;
	private SQLiteAsusNewHelper mSqlPlaceCardDetail;
	private ImageButton mIbtnMenu;
	private LinearLayout mLnlPlaceInfo, mLnlPlaceDevice, mLnlPlaceScene;
	// letq id place
	private int placeId;
	private String mName;
	private TextView mNamePlace;
	// private Boolean flagStatus = true;
	public DropListener onDrop = new DropListener() {
		public void drop(int from, int to) {
			if (from != to) {
				SceneItem s = (SceneItem) mSceneList.get(from);
				mSceneList.remove(from);
				mSceneList.add(to, s);
				mSceneAdapter.notifyDataSetChanged();
			}
		}
	};
	public DropListener onDropDevices = new DropListener() {
		public void drop(int from, int to) {
			if (from != to) {
				DeviceItem s = (DeviceItem) mDeviceList.get(from);
				mDeviceList.remove(from);
				mDeviceList.add(to, s);
				mDeviceAdapter.notifyDataSetChanged();
			}

		}
	};

	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.activity_place_card_detail);
		initActionBar(R.layout.menu_in_action_bar);
		setDisableDrawer();
		mSqlPlaceCardDetail = new SQLiteAsusNewHelper(this);
		mAddItemScene = new SceneItem();
		mDeviceUpdatePhoto = new DeviceUpdatePhoto(this);

		initView();
		initData();
		initListener();

	}

	@SuppressLint("ClickableViewAccessibility")
	private void initView() {
		// init photo upload

		// mInfoOfPlace =
		// (InfoOfPlaceView)findViewById(R.id.activity_info_of_place);
		// mInfoOfPlaceListView = (DragSortListView)
		// findViewById(R.id.lv_list_info_of_place);
		// initActionBar(R.layout.menu_in_action_bar);
		mBtnPlaceInfo = (Button) findViewById(R.id.btn_place_info);
		mBtnPlaceDevice = (Button) findViewById(R.id.btn_place_devices);
		mBtnPlaceScene = (Button) findViewById(R.id.btn_place_scenes);
		mLnlPlaceInfo = (LinearLayout) findViewById(R.id.lnl_place_info);
		mLnlPlaceDevice = (LinearLayout) findViewById(R.id.lnl_place_devices);
		mLnlPlaceScene = (LinearLayout) findViewById(R.id.lnl_place_scenes);
		mDeviceListView = (DragSortListView) findViewById(R.id.lv_list_devices);
		mSceneListView = (DragSortListView) findViewById(R.id.lv_list_scenes);
		mNamePlace = (TextView) findViewById(R.id.title_text);
		mInfoOfPlace = (InfoOfPlaceView) findViewById(R.id.activity_info_of_place);

		setEnaleTab(2);

		mController = new DragSortController(mDeviceListView);
		mController.setDragHandleId(R.id.rlt_drag);
		mController.setRemoveEnabled(false);
		mController.setSortEnabled(true);
		mController.setDragInitMode(2);
		mDeviceListView.setFloatViewManager(mController);
		mDeviceListView.setOnTouchListener(mController);
		mDeviceListView.setDragEnabled(true);
		mDeviceListView.setDropListener(onDrop);

		mControllerDevice = new DragSortController(mDeviceListView);
		mControllerDevice.setDragHandleId(R.id.rlt_drag);
		mControllerDevice.setRemoveEnabled(false);
		mControllerDevice.setSortEnabled(true);
		mControllerDevice.setDragInitMode(2);
		mDeviceListView.setFloatViewManager(mControllerDevice);
		mDeviceListView.setOnTouchListener(mControllerDevice);
		mDeviceListView.setDragEnabled(true);
		mDeviceListView.setDropListener(onDropDevices);

		mController = new DragSortController(mSceneListView);
		mController.setDragHandleId(R.id.rlt_drag_scene);
		mController.setRemoveEnabled(false);
		mController.setSortEnabled(true);
		mController.setDragInitMode(2);
		mSceneListView.setFloatViewManager(mController);
		mSceneListView.setOnTouchListener(mController);
		mSceneListView.setDragEnabled(true);
		mSceneListView.setDropListener(onDrop);
	}

	private void initData() {

		mDeviceList = new ArrayList<DeviceItem>();
		// mSQLHelper = new SQLiteAsusNewHelper(this);
		// DBHelper.addDataTest(mSQLHelper);

		mContext = PlaceCardDetailActivity.this;
		mSQLHelper = new SQLiteAsusNewHelper(mContext);
		// DBHelper.addDataTest(mSQLHelper);

		Bundle bundle = getIntent().getExtras();
		if (bundle != null) {
			placeId = bundle.getInt(Constants.DATA_ID_PLACE);
			mName = bundle.getString(Constants.DATA_NAME_PLACE);
			mDeviceList = mSQLHelper.getAllDevice(placeId);
			mDeviceAdapter = new PlaceDeviceCardAdapter(this, mDeviceList,
					mDeviceUpdatePhoto);
			mDeviceListView.setAdapter(mDeviceAdapter);
			mNamePlace.setText(mName);
		}

		// mDeviceList = mSQLHelper.getAllDevice(placeId);
		// DBHelper.addDataTest(mSQLHelper);
		/*
		 * Bundle bundle = getIntent().getExtras();
		 * 
		 * if (bundle != null) { placeId =
		 * bundle.getInt(Constants.DATA_ID_PLACE); mName =
		 * bundle.getString(Constants.DATA_NAME_PLACE); mDeviceList =
		 * mSQLHelper.getAllDevice(placeId); mDeviceAdapter = new
		 * PlaceDeviceCardAdapter(this, mDeviceList, mDeviceUpdatePhoto);
		 * mDeviceListView.setAdapter(mDeviceAdapter);
		 * mNamePlace.setText(mName); }
		 * 
		 * // DBHelper.addDataTest(mSQLHelper); /* Bundle bundle =
		 * getIntent().getExtras(); >>>>>>> .r309 if (bundle != null) { placeId
		 * = bundle.getInt(Constants.DATA_ID_PLACE); mName =
		 * bundle.getString(Constants.DATA_NAME_PLACE); mDeviceList =
		 * mSQLHelper.getAllDevice(2); mDeviceAdapter = new
		 * PlaceDeviceCardAdapter(this, mDeviceList,mDeviceUpdatePhoto);
		 * mDeviceListView.setAdapter(mDeviceAdapter); //
		 * mNamePlace.setText(mName); }
		 * 
		 * mDeviceList = mSQLHelper.getAllDevice(placeId); mDeviceAdapter = new
		 * PlaceDeviceCardAdapter(this, mDeviceList,mDeviceUpdatePhoto);
		 * mDeviceListView.setAdapter(mDeviceAdapter); //
		 * DBHelper.addDataTest(mSQLHelper); /* Bundle bundle =
		 * getIntent().getExtras(); if (bundle != null) { placeId =
		 * bundle.getInt("idplace"); mName = bundle.getString("NamePlace"); }
		 * 
		 * Intent intentFormSelectDevice = getIntent(); Bundle
		 * bundleFormSelectDevice = intentFormSelectDevice
		 * .getBundleExtra("Data"); itemPlace = (PlaceItem)
		 * bundleFormSelectDevice .getSerializable("PlaceNew");
		 * mNamePlace.setText(itemPlace.getPlaceName().toString());
		 */
		// Set data data for Tab Info
		// mInfoOfPlace.setData(placeId);

		// Set data for Tab Devices
		// mDeviceList = mSQLHelper.getAllDevice(2);
		// mDeviceAdapter = new PlaceDeviceCardAdapter(this, mDeviceList);

		// mDeviceListView.setAdapter(mDeviceAdapter);
		// Set data for scene
		mSceneList = new ArrayList<SceneItem>();
		mSceneList = mSQLHelper.getSceneByPlaceId(placeId);
		mSceneAdapter = new SceneAdapter(this, mSceneList, mDeviceUpdatePhoto);
		mSceneListView.setAdapter(mSceneAdapter);
		//

	}

	private void initListener() {
		mBtnPlaceInfo.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				setEnaleTab(1);
			}
		});
		mBtnPlaceDevice.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				setEnaleTab(2);
			}
		});
		mBtnPlaceScene.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				setEnaleTab(3);
			}
		});
	}

	private void setEnaleTab(int index) {
		switch (index) {
		case 1:
			mBtnPlaceInfo.setBackgroundResource(R.drawable.button_pressed);
			mBtnPlaceDevice.setBackgroundResource(R.drawable.button_normal);
			mBtnPlaceScene.setBackgroundResource(R.drawable.button_normal);
			mBtnPlaceInfo.setTypeface(Typeface.DEFAULT_BOLD);
			mBtnPlaceInfo.setTextColor(getResources().getColor(R.color.black));
			mBtnPlaceDevice.setTypeface(Typeface.DEFAULT);
			mBtnPlaceDevice.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceScene.setTypeface(Typeface.DEFAULT);
			mBtnPlaceScene.setTextColor(getResources().getColor(
					R.color.strong_grey));

			mBtnPlaceInfo.setTextColor(getResources().getColor(R.color.black));
			mBtnPlaceInfo.setTypeface(Typeface.DEFAULT_BOLD);
			mBtnPlaceDevice.setTypeface(Typeface.DEFAULT);
			mBtnPlaceDevice.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceScene.setTypeface(Typeface.DEFAULT);
			mBtnPlaceScene.setTextColor(getResources().getColor(
					R.color.strong_grey));

			mLnlPlaceInfo.setVisibility(View.VISIBLE);
			mLnlPlaceDevice.setVisibility(View.GONE);
			mLnlPlaceScene.setVisibility(View.GONE);
			break;
		case 2:
			mBtnPlaceInfo.setBackgroundResource(R.drawable.button_normal);
			mBtnPlaceDevice.setBackgroundResource(R.drawable.button_pressed);
			mBtnPlaceScene.setBackgroundResource(R.drawable.button_normal);
			mBtnPlaceInfo.setTypeface(Typeface.DEFAULT);
			mBtnPlaceInfo.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceDevice.setTypeface(Typeface.DEFAULT_BOLD);
			mBtnPlaceDevice
					.setTextColor(getResources().getColor(R.color.black));
			mBtnPlaceScene.setTypeface(Typeface.DEFAULT);
			mBtnPlaceScene.setTextColor(getResources().getColor(
					R.color.strong_grey));

			mBtnPlaceInfo.setTypeface(Typeface.DEFAULT);
			mBtnPlaceInfo.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceDevice.setTypeface(Typeface.DEFAULT_BOLD);
			mBtnPlaceDevice
					.setTextColor(getResources().getColor(R.color.black));
			mBtnPlaceScene.setTypeface(Typeface.DEFAULT);
			mBtnPlaceScene.setTextColor(getResources().getColor(
					R.color.strong_grey));

			mLnlPlaceInfo.setVisibility(View.GONE);
			mLnlPlaceDevice.setVisibility(View.VISIBLE);
			mLnlPlaceScene.setVisibility(View.GONE);
			break;
		case 3:
		default:
			mBtnPlaceInfo.setBackgroundResource(R.drawable.button_normal);
			mBtnPlaceDevice.setBackgroundResource(R.drawable.button_normal);
			mBtnPlaceScene.setBackgroundResource(R.drawable.button_pressed);
			mBtnPlaceInfo.setTypeface(Typeface.DEFAULT);
			mBtnPlaceInfo.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceDevice.setTypeface(Typeface.DEFAULT);
			mBtnPlaceDevice.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceScene.setTypeface(Typeface.DEFAULT_BOLD);
			mBtnPlaceScene.setTextColor(getResources().getColor(R.color.black));

			mBtnPlaceInfo.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceDevice.setTypeface(Typeface.DEFAULT);
			mBtnPlaceDevice.setTextColor(getResources().getColor(
					R.color.strong_grey));
			mBtnPlaceScene.setTypeface(Typeface.DEFAULT_BOLD);
			mBtnPlaceScene.setTextColor(getResources().getColor(R.color.black));
			mLnlPlaceInfo.setVisibility(View.GONE);
			mLnlPlaceDevice.setVisibility(View.GONE);
			mLnlPlaceScene.setVisibility(View.VISIBLE);
			break;
		}
	}

	@Override
	protected void initActionBar(int actionBarView) {
		// TODO Auto-generated method stub
		super.initActionBar(actionBarView);
		mIbtnMenu = (ImageButton) this.findViewById(R.id.btn_menu);
		mIbtnMenu.setOnClickListener(this);
		ImageButton btnAdd = (ImageButton) this.findViewById(R.id.btn_add);
		btnAdd.setOnClickListener(this);
		ImageView imgBack = (ImageView) this.findViewById(R.id.btn_back);
		imgBack.setOnClickListener(this);
	}

	public void setItemOfMenu(int flag) {
		if (flag == 0) {
			PopupMenu popupMenu = new PopupMenu(PlaceCardDetailActivity.this,
					mIbtnMenu);
			popupMenu.inflate(R.menu.popup_menu);
			popupMenu.setOnMenuItemClickListener(this);
			popupMenu.show();
			popupMenu.setOnMenuItemClickListener(this);
		} else if (flag == 1) {
			setDialogPlaceDetail();
		}

	}

	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (resultCode == RESULT_OK) {
			if (requestCode == DeviceUpdatePhoto.cameraCapture) {
				mDeviceUpdatePhoto.performcrop(mDeviceUpdatePhoto.getPicUri());
			} else if (requestCode == DeviceUpdatePhoto.picCrop) {
				Toast.makeText(getApplicationContext(), "DONE",
						Toast.LENGTH_SHORT).show();
			}
			if (requestCode == DeviceUpdatePhoto.pickFromFile) {
				mDeviceUpdatePhoto.performcrop(data.getData());
			}
		}
	}

	@Override
	public boolean onMenuItemClick(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.item_update_photo:
			mDeviceUpdatePhoto.updatePhoto();
			break;
		case R.id.item_remane:
			/*
			 * BaseDeviceDialog renamePlaceCard = new BaseDeviceDialog( this);
			 * renamePlaceCard.editNameDevice("1");
			 */
			break;
		case R.id.item_change_capability:
			setActionOnItemOfMenu(2);
			break;
		case R.id.item_move_devices_to:
			if (mDeviceList.size() > 0) {
				moveDeviceCard();
			} else
				Toast.makeText(mContext, "this place hasn't device",
						Toast.LENGTH_LONG).show();

			break;
		case R.id.item_remove_this_place:
			removeThisPlace();
			break;
		default:
			break;
		}
		return false;
	}

	public void setActionOnItemOfMenu(int flag) {
		switch (flag) {
		case 2:
			final AudiDialog dialogPlaceDetail = new AudiDialog(this);
			dialogPlaceDetail
					.setLayout(R.layout.custom_dialog_place_card_detail);
			/* dialogPlaceDetail.setView(deleteDialogView); */
			final Button mBtnCancelChangeCapability = (Button) dialogPlaceDetail
					.findViewById(R.id.btn_cancel_change_capability);
			final TextView txtPublic = (TextView) dialogPlaceDetail
					.findViewById(R.id.txt_select_capability_type_public);
			txtPublic.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub

				}
			});
			@SuppressWarnings("unused")
			final TextView txtcapability = (TextView) dialogPlaceDetail
					.findViewById(R.id.txt_select_capability_type_public);
			txtPublic.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub

				}
			});
			mBtnCancelChangeCapability
					.setOnClickListener(new OnClickListener() {
						@Override
						public void onClick(View arg0) {
							// TODO Auto-generated method stub
							dialogPlaceDetail.dismiss();
						}
					});
			dialogPlaceDetail.show();
			break;
		default:
			break;
		}
	}

	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.btn_menu:
			setItemOfMenu(0);
			break;
		case R.id.btn_add:
			setItemOfMenu(1);
			break;
		case R.id.btn_back:

			/*
			 * startActivity(new Intent(PlaceCardDetailActivity.this,
			 * PlaceCardActivity.class));
			 */
			finish();
			break;
		default:
			break;
		}
	}

	public void moveDeviceCard() {

		Intent intentAddDevices = new Intent(PlaceCardDetailActivity.this,
				MoveDeviceInfoActivity.class);
		Bundle mBundle = new Bundle();
		mBundle.putSerializable("dataDevice", mDeviceList);
		intentAddDevices.putExtras(mBundle);
		startActivity(intentAddDevices);
		finish();

	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (buttonView == mchkWhite && buttonView.isChecked()) {
			setColorforCheckbox(mchkWhite);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.WHITE
					.ordinal());
		}
		if (buttonView == mchkRed && buttonView.isChecked()) {
			setColorforCheckbox(mchkRed);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.RED
					.ordinal());
		}
		if (buttonView == mchkOrange && buttonView.isChecked()) {
			setColorforCheckbox(mchkOrange);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.ORANGE
					.ordinal());
		}
		if (buttonView == mchkYellow && buttonView.isChecked()) {
			setColorforCheckbox(mchkYellow);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.YELLOW
					.ordinal());
		}
		if (buttonView == mchkSilver && buttonView.isChecked()) {
			setColorforCheckbox(mchkSilver);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.GREY
					.ordinal());
		}
		if (buttonView == mchkSkyBlue && buttonView.isChecked()) {
			setColorforCheckbox(mchkSkyBlue);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.BLUE
					.ordinal());
		}
		if (buttonView == mchkSpringGreen && buttonView.isChecked()) {
			setColorforCheckbox(mchkSpringGreen);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.SBLUE
					.ordinal());
		}
		if (buttonView == mchkYellowGreen && buttonView.isChecked()) {
			setColorforCheckbox(mchkYellowGreen);
			mAddItemScene.setSceneBackground(Constants.SCENE_COLOR_TYPE.GREEN
					.ordinal());
		}

		int sceneId = mSqlPlaceCardDetail.addScene(mAddItemScene);
		dialogSelectColor.dismiss();
		Intent intentStatusDevices = new Intent(PlaceCardDetailActivity.this,
				StatusDevicesActivity.class);
		Bundle bundleStatusDevices = new Bundle();
		bundleStatusDevices.putInt(Constants.DATA_ID_PLACE, placeId);
		bundleStatusDevices.putString(Constants.DATA_NAME_PLACE, mName);
		bundleStatusDevices.putInt(Constants.DATA_ID_SCENE, sceneId);
		bundleStatusDevices.putString(Constants.DATA_NAME_SCENE,
				mAddItemScene.getSceneTitle());
		intentStatusDevices.putExtras(bundleStatusDevices);
		startActivity(intentStatusDevices);
	}

	private void setColorforCheckbox(CheckBox checkbox) {
		checkbox.setButtonDrawable(R.drawable.ic_checked);

	}

	private void selectColor() {
		dialogSelectColor = new AudiDialog(PlaceCardDetailActivity.this);
		dialogSelectColor.setLayout(R.layout.checkbox_item);
		dialogSelectColor.show();
		Button btnCancelColor = (Button) dialogSelectColor
				.findViewById(R.id.btn_cancel_change_mode_color);
		btnCancelColor.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				dialogSelectColor.dismiss();
			}
		});
		dialogSelectColor.show();
		mchkWhite = (CheckBox) dialogSelectColor.findViewById(R.id.chk_white);
		mchkWhite.setOnCheckedChangeListener(this);

		mchkRed = (CheckBox) dialogSelectColor.findViewById(R.id.chk_red);
		mchkRed.setOnCheckedChangeListener(this);
		mchkOrange = (CheckBox) dialogSelectColor.findViewById(R.id.chk_orange);
		mchkOrange.setOnCheckedChangeListener(this);
		mchkYellow = (CheckBox) dialogSelectColor.findViewById(R.id.chk_yellow);
		mchkYellow.setOnCheckedChangeListener(this);
		mchkSilver = (CheckBox) dialogSelectColor.findViewById(R.id.chk_silver);
		mchkSilver.setOnCheckedChangeListener(this);
		mchkSkyBlue = (CheckBox) dialogSelectColor
				.findViewById(R.id.chk_sky_blue);
		mchkSkyBlue.setOnCheckedChangeListener(this);
		mchkSpringGreen = (CheckBox) dialogSelectColor
				.findViewById(R.id.chk_spring_green);
		mchkSpringGreen.setOnCheckedChangeListener(this);
		mchkYellowGreen = (CheckBox) dialogSelectColor
				.findViewById(R.id.chk_yellow_green);
		mchkYellowGreen.setOnCheckedChangeListener(this);
	}

	/*
	 * function Remove this Place
	 */
	public void removeThisPlace() {
		final Dialog dialog = new Dialog(PlaceCardDetailActivity.this);
		dialog.setContentView(R.layout.dialog_remove_place_card);
		dialog.setTitle("Remove this place");
		dialog.show();
		Button buttondialog = (Button) dialog.findViewById(R.id.id_yes_dialog);
		buttondialog.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				/*
				 * Intent i = new Intent(PlaceCardDetailActivity.this,
				 * PlaceCardActivity.class);
				 */
				mSQLHelper.updatePlaceIdNew(placeId, 1);
				mSQLHelper.deletePlace(placeId);
				dialog.cancel();
				// startActivity(i);
				finish();

			}
		});
		Button mBtnNo = (Button) dialog.findViewById(R.id.id_no_dialog);
		mBtnNo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialog.cancel();

			}
		});
	}

	private void setDialogPlaceDetail() {

		final AudiDialog dialogPlaceDetail = new AudiDialog(
				PlaceCardDetailActivity.this);
		dialogPlaceDetail.setLayout(R.layout.notice_place_detail);
		dialogPlaceDetail.show();

		TextView mTxtAddDevices = (TextView) dialogPlaceDetail
				.findViewById(R.id.text_add_devices);
		TextView mTxtAddNewScene = (TextView) dialogPlaceDetail
				.findViewById(R.id.text_add_new_scene);

		mTxtAddNewScene.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				dialogPlaceDetail.dismiss();
				final AudiDialog dialogNewSceneName = new AudiDialog(
						PlaceCardDetailActivity.this);
				dialogNewSceneName.setLayout(R.layout.new_scene_name_dialog);
				dialogNewSceneName.show();

				@SuppressWarnings("unused")
				final EditText mEdtNewScene = (EditText) dialogNewSceneName
						.findViewById(R.id.edt_new_scene);

				/*
				 * EditText mEdtNewScene = (EditText) dialogNewSceneName
				 * .findViewById(R.id.edt_new_scene);
				 */

				Button mBtnNewSceneCancel = (Button) dialogNewSceneName
						.findViewById(R.id.btn_new_scene_cancel);
				final Button mBtnNewSceneOk = (Button) dialogNewSceneName
						.findViewById(R.id.btn_new_scene_ok);

				mBtnNewSceneCancel.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method
						// stub
						dialogNewSceneName.dismiss();

					}
				});
				//
				// mBtnNewSceneOk.setClickable(false);
				// mBtnNewSceneOk.setAlpha(0.5f);
				// mEdtNewScene.setOnKeyListener(new OnKeyListener()
				// {
				//
				// @Override
				// public boolean onKey(View arg0, int arg1,
				// KeyEvent arg2) {
				// // TODO Auto-generated method stub
				// if(mEdtNewScene.getText().toString().equals("")){
				// mBtnNewSceneOk.setClickable(false);
				// mBtnNewSceneOk.setAlpha(0.5f);
				//
				// } else{
				// mBtnNewSceneOk.setAlpha(1f);
				mBtnNewSceneOk.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method
						// stub
						dialogNewSceneName.dismiss();
						mAddItemScene.setPlaceId(placeId);
						mAddItemScene.setSceneTitle(mEdtNewScene.getText()
								.toString());
						if (mSqlPlaceCardDetail.checkExistScene(mAddItemScene)) {
							final AudiDialog dialogNewSceneNotice = new AudiDialog(
									PlaceCardDetailActivity.this);
							dialogNewSceneNotice
									.setLayout(R.layout.notice_new_scene_dialog);
							dialogNewSceneNotice.show();
							Button mBtnOkNotice = (Button) dialogNewSceneNotice
									.findViewById(R.id.btn_notice_ok);
							mBtnOkNotice
									.setOnClickListener(new OnClickListener() {

										@Override
										public void onClick(View arg0) {
											dialogNewSceneNotice.dismiss();
										}
									});
						} else {
							selectColor();

						}

					}
				});
			}
		});

		mTxtAddDevices.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialogPlaceDetail.dismiss();

			}
		});
	}

	@Override
	public void onRefreshData() {
		// TODO Auto-generated method stub

	}

}